#include <bits/stdc++.h>
using namespace std;
struct car{
    int d,v,a;
};
int t,n,m,l,v,b[100001],cnt=0;
car a[100001];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        cnt=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>a[i].d>>a[i].v>>a[i].a;
        }
        for(int i=1;i<=m;i++){
            cin>>b[i];
        }
        sort(b+1,b+m+1);
        for(int i=1;i<=n;i++){
            if(a[i].v>v){
                cnt++;
            }
        }
        cout<<cnt<<" "<<(m-1);
    }
    return 0;
}
